package com.lenovo.manufacture;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.just.agentweb.AgentWeb;
import com.just.agentweb.WebChromeClient;

/**
 * @author Amoly
 * @date 2019/10/24.
 * GitHub：
 * email：
 * description：
 */
public class TestActivity extends AppCompatActivity {
    private ImageView back;
    private TextView text;
    private LinearLayout web;
    private AgentWeb agentWeb;
    private static String URL="file:///android_asset/";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        initView();
        initfunction();
    }

    private void initView() {
        back = (ImageView) findViewById(R.id.back);
        text = (TextView) findViewById(R.id.text);
        web = (LinearLayout) findViewById(R.id.web);
    }

    private void initfunction() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        String data = getIntent().getStringExtra("data");
        switch (data){
            case "0":
                setweb("lightFragment.html");
                break;
            case "1":
                setweb("file2.html");
                break;
            case "2":
                setweb("file3.html");
                break;
            case "3":
                setweb("file4.html");
                break;
            case "4":
                setweb("file5.html");
                break;
            case "5":
                setweb("file6.html");
                break;
            case "6":
                setweb("file7.html");
                break;
            case "7":
                setweb("file8.html");
                break;
            case "8":
                setweb("file9.html");
                break;
        }

    }
    public void  setweb(String url){
        agentWeb=AgentWeb.with(this)
                .setAgentWebParent(web,new LinearLayout.LayoutParams(-1,-1))
                .useDefaultIndicator()
                .setWebChromeClient(new WebChromeClient(){
                    @Override
                    public void onReceivedTitle(WebView view, String title) {
                        super.onReceivedTitle(view, title);
                        text.setText(title);
                    }
                })
                .createAgentWeb()
                .ready()
                .go(URL+url);
        agentWeb.getJsInterfaceHolder().addJavaObject("android",new Utils(this));
    }


}
